<template>
	<Content title="生产提报详情">
		<view class="device-details">
			<view class="content">
				<view class="main-box">
					<u-form labelPosition="left" :model="model" labelWidth="80" labelAlign="left" :rules="rules"
						ref="uForm">
						<view class="info-box">
							<view class="title">
								<text class="txt u-line-1">工单号 {{ id }}</text>
								<view class="tag-box">
									<u-tag shape="circle" :text="data.state" :borderColor="getColor(data.state)"
										:bgColor="getColor(data.state)"></u-tag>
								</view>
							</view>

							<view class="text-box">
								<text class="label">产品编号:</text>
								<text class="value">{{ data.materialCode }}</text>
							</view>
							<view class="text-box">
								<text class="label">产品名称:</text>
								<text class="value">{{ data.materialName }}</text>
							</view>
							<view class="text-box">
								<text class="label">产品型号:</text>
								<text class="value">{{ data.materialModel }}</text>
							</view>
							<view class="text-box">
								<text class="label">计划数量:</text>
								<text class="value">{{ data.planProduceQuantity }}</text>
							</view>
							<view class="text-box">
								<text class="label">生产数量:</text>
								<text class="value">{{ data.produceQuantity }}</text>
							</view>
							<view class="text-box">
								<text class="label">已报工数量:</text>
								<text class="value">{{ data.reportedQuantity }}</text>
							</view>
							<view class="text-box">
								<text class="label">产品单重:</text>
								<text class="value">{{ data.weight }}</text>
							</view>
							<view class="text-box">
								<text class="label">重量单位:</text>
								<text class="value">{{ data.weightUnit }}</text>
							</view>
							<view class="text-box">
								<text class="label">报废数量:</text>
								<text class="value">{{ data.scrapQuantity }}</text>
							</view>
							<view class="text-box" v-if="data.cuttingPlanCode">
								<text class="label">开料详情:</text>
								<text class="value" @click="selectCuttingPlan(data)"
									style="color: #3c9cff">查看开料计划单</text>
							</view>
						</view>

						<view class="info-box" v-if="!data.cuttingPlanCode">
							<view class="input-box">
								<u-form-item label="提报类型:" required prop="mode">
									<uni-data-select v-model="model.mode" :localdata="typeList"
										placeholder="请选择"></uni-data-select>
								</u-form-item>
							</view>
						</view>

						<view class="info-box">
							<view class="title">
								<text class="txt">提报内容</text>
							</view>
							<view class="input-box">
								<u-form-item label="班次时间:" required prop="shiftTime">
									<MyDate @change="getShiftList" v-model="model.shiftTime" placeholder="请选择"></MyDate>
								</u-form-item>
							</view>
							<view class="input-box">
								<u-form-item label="班次:" required prop="shift">
									<uni-data-select v-model="model.shift" :localdata="shiftList" @change="getShiftTime"
										placeholder="请选择"></uni-data-select>
								</u-form-item>
							</view>

							<template v-if="data.cuttingPlanCode">
								<view class="input-box">
									<u-form-item label="卷号:" prop="rollNumber" required>
										<uni-data-select v-model="model.rollNumber" :localdata="rollNumberList"
											@change="changeRollNumber" placeholder="请选择"></uni-data-select>
									</u-form-item>
								</view>
								<view class="input-box">
									<u-form-item label="卷重:" prop="rollWeight" required>
										<MyNumber class="box-input" v-model="model.rollWeight" :decimal="3"
											:halfAdjust="false" :min="0" :max="99999999.999" placeholder="请填写" />
									</u-form-item>
								</view>
							</template>

							<template v-if="model.mode === '箱码'">
								<view class="input-box">
									<!-- readonly -->
									<u-form-item label="箱码:" prop="boxCode" required @click="onFocus">
										<u-input :class="['box-input', btnName == '箱码' ? 'isThis' : '']" label readonly
											v-model="model.boxCode" placeholder="请填写" @click="onFocus">
											<!-- <div slot="suffix" @click.stop="scanCode"> -->
											<!-- </div> -->
										</u-input>
										<u-icon name="scan"></u-icon>
									</u-form-item>
								</view>
								<view class="input-box">
									<u-form-item label="件码:" prop="itemCodebyName" @click="onFocus1" required>
										<view style="width: 100%;display: flex;align-items: center;">
											<!-- disabled -->
											<u--textarea :class="['box-input', btnName == '件码' ? 'isThis' : '']"
												@click="onFocus1" v-model="model.itemCodebyName" disabled
												@confirm="test" placeholder="请填写" autoHeight>
											</u--textarea>

											<view @click.stop="scanCode1" style="margin-left: 20rpx;">
												<u-icon name="scan"></u-icon>
											</view>
										</view>
									</u-form-item>
								</view>

								<view class="item-code-list"
									v-if="model.itemCodebyList && model.itemCodebyList.length > 0">
									<view class="item-code-item" v-for="(item, index) in model.itemCodebyList"
										:key="index">
										<text class="item-label">件码{{ index + 1 }}:</text>
										<text class="item-value">{{ item.itemCode }}</text>
										<view class="delete-btn" @click="removeItemCode(index)">删除</view>
									</view>
								</view>
							</template>

							<view class="input-box">
								<u-form-item label="提报方式:" required prop="reportingMethod">
									<uni-data-select v-model="model.reportingMethod"
										:localdata="data.cuttingPlanCode ? localdata1 : localdata"
										placeholder="请选择"></uni-data-select>
								</u-form-item>
							</view>
							<view class="input-box">
								<!-- {{workInfo.cuttingPlanCode}}---{{model.reportedQuantity}} -->
								<u-form-item :label="`${model.reportingMethod==='按数量'?'入库数量':'入库重量'}`"
									class="label-fwn">
									<MyNumber class="box-input" v-model="data.reportedQuantity" :decimal="2"
										:halfAdjust="false" :min="0" :max="99999999.999" :disabled="true"
										:placeholder="data.cuttingPlanCode?'自动计算': '请输入'">
										<template slot="suffix" v-if="model.reportingMethod==='按重量'">
											{{ data.weightUnit }}
										</template>
									</MyNumber>
								</u-form-item>
							</view>
							<view class="input-box">
								<u-form-item label="入库仓库:" required prop="wareHouse">
									<uni-data-select @change="changeWareHouse" v-model="model.wareHouse"
										:localdata="wareHouses" placeholder="请选择"></uni-data-select>
								</u-form-item>
							</view>
							<view class="input-box" v-if="!data.cuttingPlanCode">
								<u-form-item label="包规:" prop="specificationsNumber">
									<u-input class="box-input" label v-model="model.specificationsNumber" rea
										placeholder="请填写" clearable readonly></u-input>
								</u-form-item>
							</view>
							<view class="input-box" v-if="!data.cuttingPlanCode">
								<u-form-item label="包数:" prop="num">
									<u-input class="box-input" label v-model="model.num" placeholder="请填写" clearable
										readonly></u-input>
								</u-form-item>
							</view>
							<view class="input-box" v-if="!data.cuttingPlanCode">
								<u-form-item label="尾箱数:" prop="boxes">
									<u-input class="box-input" label v-model="model.boxes" placeholder="请填写" clearable
										readonly></u-input>
								</u-form-item>
							</view>
							<view class="input-box">
								<u-form-item label="备注:" prop="remarks">
									<u-input class="box-input" label v-model="model.remarks" placeholder="请填写"
										clearable></u-input>
								</u-form-item>
							</view>
						</view>
						<view class="info-box select_user" @click="selectUser">
							<view class="text-box-l text-title">
								<text class="label">操作工</text>
								<view class="txt-box">
									<text class="txt" v-for="(item, index) in selectLists" :key="item.id">{{
                      item.name + (index < selectLists.length - 1 ? "," : "")
                    }}</text>
								</view>
							</view>
							<uni-icons class="icons" type="right" size="14" color="#999" />
						</view>

						<view class="info-box" v-if="data.cuttingPlanCode">
							<view class="title">
								<text class="txt">{{ model.shift }}</text>
							</view>
							<view class="input-box">
								<u-form-item required label="报工数量" prop="reportedQuantity"><!-- required -->
									<u-input class="box-input" readonly v-model="model.reportedQuantity"
										placeholder="自动计算" clearable>
									</u-input>
								</u-form-item>
							</view>
						</view>

						<template v-else>
							<view class="info-box">
								<view class="title">
									<text class="txt">{{ model.shift }}</text>
								</view>
								<view class="input-box">
									<u-form-item required :label="`报工${
                      model.reportingMethod == '按重量' ? '重量' : '数量'
                    }:`" prop="reportedQuantity">
										<MyNumber class="box-input" readonly v-model="model.reportedQuantity"
											:decimal="3" :halfAdjust="false" :min="0" :max="99999999.999"
											placeholder="请填写" clearable>
											<template slot="suffix">
												<u-icon @click.native="scanCode2" name="scan"></u-icon>
											</template>
										</MyNumber>
									</u-form-item>
								</view>
							</view>
							<template>
								<view class="info-box" v-for="(item, index) in selectLists">
									<view class="title">
										<text class="txt">{{ item.name }}</text>
									</view>
									<view class="input-box">
										<u-form-item :key="item.id" :label="`提报${
                        model.reportingMethod == '按重量' ? '重量' : '数量'
                      }:`">
											<MyNumber class="box-input" v-model="model.quantityS[index + '']"
												:decimal="3" :halfAdjust="false" :min="0" :max="99999999.999"
												:maxlength="7" @input="quantitySChange" placeholder="请填写" clearable>
												<template slot="suffix">
													<u-icon @click.native="scanCode2" name="scan"></u-icon>
												</template>
											</MyNumber>
										</u-form-item>
									</view>
								</view>
							</template>
						</template>

						<view class="info-box">
							<view class="title">
								<text class="txt u-line-1">添加图片（选填，最多5张）</text>
							</view>
							<view class="text-box">
								<!-- <text class="label">填报数量:</text> -->
								<view class="value">
									<MyUpload v-model="fileList" multiple :maxCount="5"></MyUpload>
								</view>
							</view>
						</view>
					</u-form>
				</view>
			</view>

			<view class="btn-v">
				<view class="but-box">
					<u-button class="btn" @click="toPath" type="primary" text="历史提报记录"></u-button>
					<u-button class="btn" type="primary" @click="submit" :loading="loading" :disabled="loading"
						text="提交"></u-button>
					<!-- <u-button class="btn" type="primary" text="完成"></u-button>
          <u-button class="btn" type="primary" text="开始"></u-button> -->
				</view>
			</view>
		</view>
	</Content>
</template>

<script>
	import Content from "@/components/content/index";
	import fetch from "@/utils/fetch";
	import MyDate from "@/components/myDate";
	import MyUpload from "@/components/myUpload";
	import MyNumber from "@/components/MyNumber";
	import {
		getNotice,
		setNotice,
		getUserInfo
	} from "@/store/user.js";
	import {
		initScan,
		startScan,
		stopScan
	} from "@/utils/scan";
	export default {
		components: {
			Content,
			MyDate,
			MyUpload,
			MyNumber
		},
		watch: {
			'model.rollWeight'(value) {
				if (value == 0) {
					this.$set(this.model, 'reportedQuantity', 0);
				} else {
					//卷重÷卷料料宽*条料料宽
					const data = this.rollNumberList.find(item => item.value === this.model.rollNumber);
					let reportedQuantity = parseFloat(value / data.rollMaterialWidth * data.materialWidth);
					this.$set(this.model, 'reportedQuantity', Math.floor(reportedQuantity * Math.pow(10, 3)) / Math.pow(
						10, 3));
				}
			}
		},
		data() {
			return {
				btnName: "",
				id: "",
				model: {
					mode: "正常",
					shift: "",
					shiftId: "",
					shiftTime: "",
					warehouseId: "",
					reportingMethod: "按数量",
					reportedQuantity: "",
					itemCodebyName: "",
					itemCodebyList: [],
					boxCode: "",
					numberOfPiece: 0,
					rollNumber: "",
					rollWeight: "",
					quantityS: {},
				},
				isFocus: false,
				loading: false,
				wareHouses: [],
				rollNumberList: [],
				rules: {
					mode: {
						required: true,
						message: "请选择",
						trigger: ["blur", "change"],
					},
					shift: {
						required: true,
						message: "请选择",
						trigger: ["blur", "change"],
					},
					shiftTime: {
						required: true,
						message: "请选择",
						trigger: ["blur", "change"],
					},
					reportingMethod: {
						required: true,
						message: "请选择",
						trigger: ["blur", "change"],
					},
					wareHouse: {
						required: true,
						message: "请选择",
						trigger: ["blur", "change"],
					},
					boxCode: {
						required: true,
						message: "请选择",
						trigger: ["blur", "change"],
					},
					itemCodebyList: {
						type: "array",
						required: true,
						message: "请选择",
						trigger: ["blur", "change"],
					},
					reportedQuantity: {
						type: "number",
						required: true,
						message: "请填写",
						trigger: ["blur", "change"],
					},
				},
				navIndex: 0,
				type: "1",
				data: {
					cuttingPlanCode: true,
				},
				localdata: [{
						text: "按重量",
						value: "按重量",
					},
					{
						text: "按数量",
						value: "按数量",
					},
				],
				localdata1: [{
					text: "按数量",
					value: "按数量",
				}, ],
				typeList: [{
						text: "正常提报",
						value: "正常",
					},
					{
						text: "箱码绑定",
						value: "箱码",
					},
				],
				fileList: [],
				shiftList: [],
				userList: [],
				selectList: [],
				selectLists: [],
				itemCode: 0,
			};
		},
		onLoad: function(option) {
			//option为object类型，会序列化上个页面传递的参数
			this.id = option.workOrder;
		},
		onHide() {
			stopScan();
		},
		onReady: function() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			if (this.$refs.uForm) this.$refs.uForm.setRules(this.rules);
		},
		onShow: function() {
			const that = this;
			const userInfo = getUserInfo();
			const arr = [{
				empno: userInfo.empno,
				id: userInfo.userId,
				name: userInfo.realname,
			}, ];
			that.selectList = uni.getStorageSync("getSelectList") || [userInfo.userId];
			that.selectLists = uni.getStorageSync("getSelectLists") || arr;
			let obj = {};
			let obj1 = {};
			that.selectLists.map((item, index) => {
				obj[index + ""] = "";
				obj1["quantityS." + index] = {
					required: true,
					message: "请选择",
					trigger: ["blur", "change"],
				};
				obj.length = that.selectLists.length;
			});
			this.rules = Object.assign(this.rules, obj1);
			this.model.quantityS = obj;
			initScan(this.scanSuccess);
			startScan();
		},
		computed: {},
		mounted() {
			this.getList();
		},
		methods: {
			test() {
				this.checkItemCodeBind(this.model.itemCodebyName)
				// this.addBoxData(this.model.itemCodebyName)
			},
			// 修改 scanSuccess 方法中的件码处理逻辑
			async scanSuccess(code) {
				const that = this;
				if (this.btnName == "箱码") {
					that.model.boxCode = code;
				} else if (this.btnName == "件码") {
					this.checkItemCodeBind(code);
					// this.addBoxData(code)
				}
			},
			// 修改 checkItemCodeBind 方法
			checkItemCodeBind(itemCode) {
				console.log(itemCode, 'itemCode');
				fetch("get", "/dms/boxItemCodeBinding/checkBind", {
					itemCode: itemCode,
					materialCode: this.data.materialCode
				}).then(res => {
					if (res.code == 200) {
						this.addBoxData(itemCode)
					} else {
						uni.$emit("openToast", {
							type: "error",
							title: res.msg,
						});
						return false;
					}
				})
				// try {
				// 	const response = await fetch("get", "/dms/boxItemCodeBinding/checkBind", {
				// 		itemCode: itemCode
				// 	});
				// 	console.log('校验接口返回数据:', response);
				// 	return response;
				// } catch (error) {
				// 	console.error('校验件码绑定失败:', error);
				// 	// 返回一个包含错误信息的对象，确保 code 不是 200
				// 	return {
				// 		code: error.code || 500,
				// 		message: error.message || "校验件码绑定时发生错误"
				// 	};
				// }
			},


			// 修改 addBoxData 方法，确保只有在校验通过后才添加
			addBoxData(res) {
				const that = this;
				// 再次检查是否已存在（双重保障）
				if (that.model.itemCodebyList.some((item) => item.itemCode == res)) {
					uni.$emit("openToast", {
						type: "error",
						title: "不能重复扫码",
					});
					return;
				}
				// 添加新件码
				that.model.itemCodebyList.push({
					itemCode: res,
				});
				that.updateItemCodeDisplay();
			},
			updateItemCodeDisplay() {
				this.model.itemCodebyName = this.model.itemCodebyList
					.map((item) => item.itemCode)
					.join(",");
				this.model.numberOfPiece = this.model.itemCodebyList.length;
				this.model.reportedQuantity = this.model.itemCodebyList.length;
			},

			// 新增：删除件码
			removeItemCode(index) {
				this.model.itemCodebyList.splice(index, 1);
				this.updateItemCodeDisplay();
			},
			scanCode() {
				// 允许从相机和相册扫码
				const that = this;
				uni.scanCode({
					success: function(res) {
						that.model.boxCode = res.result;
					},
				});
			},
			onFocus() {
				console.log(11);
				if (this.btnName == "箱码") {
					this.btnName = ""
				} else this.btnName = "箱码"
			},
			onFocus1() {
				if (this.btnName == "件码") {
					this.btnName = "";
				} else this.btnName = "件码";
			},
			scanCode1() {
				// 允许从相机和相册扫码
				const that = this;
				uni.scanCode({
					success: function(res) {
						that.checkItemCodeBind(res.result);
					},
				});
			},
			scanCode2() {
				// 允许从相机和相册扫码
				const that = this;
				uni.scanCode({
					success: function(res) {
						console.log("条码类型：" + res.scanType);
						console.log("条码内容：" + res.result);
						// 2000152-001-001;310000090001;20231116;669;200001102356A-0002-001
						// 310000090001;DJ-416.5;5000;100001102356A-0002-001
						//   res.result = "310000090001;DJ-416.5;5000;100001102356A-0002-001";
						const arr = res.result.split(";") || [];
						console.log(arr, that.data.materialCode);
						const i = arr.findIndex((item) => item === that.data.materialCode);
						if (i !== -1) {
							let val = i === 0 ? arr[2] : arr[3];
							that.model.reportedQuantity = val ? val.toFixed(2) : "";
						} else {
							uni.$emit("openToast", {
								type: "error",
								icon: "error",
								title: "产品编号不一致!",
							});
						}
					},
				});
			},
			selectCuttingPlan(item) {
				uni.navigateTo({
					url: "/pages/staging/workshop-production/select-cutting-plan?cuttingPlanCode=" +
						item.cuttingPlanCode,
					animationType: "pop-in",
				});
			},
			changeRollNumber(val, obj) {
				console.log("changeRollNumber", val, obj);
				this.model.rollWeight = obj.rollWeight;
				// 卷重÷卷料料宽*条料料宽*条数
				// itemNum: 1             条数
				// materialWidth: 10      条料料宽
				// rollMaterialWidth: 20  卷料料宽
				// rollNumber: "4"        卷号
				// rollWeight: 1000       卷重
				let num =
					(obj.rollWeight / obj.rollMaterialWidth) *
					obj.materialWidth *
					obj.itemNum;
				this.model.reportedQuantity = Math.floor(num * Math.pow(10, 3)) / Math.pow(10, 3)
				console.log(
					"model.reportedQuantity--------",
					this.model.reportedQuantity
				);
			},
			toPath() {
				uni.navigateTo({
					url: "/pages/staging/production-reporting/reporting-records?workOrder=" +
						this.id,
					animationType: "pop-in",
				});
			},
			selectUser() {
				uni.navigateTo({
					url: "/pages/staging/production-reporting/operator1",
					animationType: "pop-in",
				});
			},
			getColor(item2) {
				return item2 == "待排产" ?
					"#E5963A" :
					item2 == "已排产" ?
					"#998BF2" :
					item2 == "下发" ?
					"#6BBEE1" :
					item2 == "生产" ?
					"#73D8A6" :
					item2 == "中断" ?
					"#D48B3E" :
					item2 == "暂停" ?
					"#D8BE49" :
					item2 == "完成" ?
					"#4668E2" :
					item2 == "转产中" ?
					"#E794C9" :
					item2 == "转产完成" ?
					"#C25BC6" :
					item2 == "调机中" ?
					"#D8B2F2" :
					item2 == "调机完成" ?
					"#8698F6" :
					item2 == "拆模" ?
					"#EA709F" :
					"#31b099";
			},
			getShiftTime(val, data) {
				console.log("getShiftTime", val, data);
				this.model.shiftId = data.id;
			},
			changeWareHouse(val, data) {
				console.log("changeWareHouse", val, data);
				this.model.warehouseId = data.id;
			},
			getList() {
				fetch("get", "/dms/mobile/getRoductionReporting", {
					workOrder: this.id,
				}).then((res) => {
					this.data = res.data;
					if (this.data.cuttingPlanCode) {
						this.model.reportingMethod = "按数量";
						this.rollNumberList = res.data.cuttingPlanList.map((item) => {
							return {
								...item,
								text: item.rollNumber,
								value: item.rollNumber,
							};
						});
						if (res.data.cuttingPlanList && res.data.cuttingPlanList[0]) {
							this.model.rollNumber = res.data.cuttingPlanList[0].rollNumber;
							this.changeRollNumber(
								this.model.rollNumber,
								res.data.cuttingPlanList[0]
							);
						}
					}
					this.model.shift = res.data?.shift;
					this.model.specificationsNumber = res.data?.specificationsNumber;
					this.model.shiftTime =
						res.data.shiftTime || this.$dayjs(new Date()).format("YYYY-MM-DD");
					this.getShiftList();
					this.getWareHouseList();
				});
			},
			//班次列表
			getShiftList() {
				const that = this;
				fetch("get", "/dms/mobile/getShiftList", {
					deviceNo: that.data.deviceCode,
					shiftDate: that.model.shiftTime,
				}).then((res) => {
					const now = that.$dayjs().format("YYYY-MM-DD") + " ";
					const now1 = that.$dayjs().add(1, "day").format("YYYY-MM-DD") + " ";
					const newDate = that.$dayjs().format("YYYY-MM-DD HH:mm:ss");
					that.shiftList = res.data.map((item) => {
						const startTime = now + item.shiftStartTime;
						let endTime = now + item.shiftEndTime;
						if (endTime < startTime) {
							endTime = now1 + item.shiftEndTime;
						}
						console.log("startTime, endTime", startTime, endTime, newDate);
						if (newDate > startTime && newDate < endTime) {
							that.model.shift = item.shift;
							that.model.shiftId = item.id;
						}
						return {
							...item,
							value: item.shift,
							text: item.shift,
						};
					});
					if (!that.model.shift) {
						that.model.shift = that.shiftList[0].shift;
						that.model.shiftId = that.shiftList[0].id;
					}

					console.log("that.shiftList", that.shiftList);
				});
			},
			getWareHouseList() {
				fetch("get", "/dms/mobileEnd/getQualifiedWarehouse", {
					deviceNo: this.data.deviceCode,
				}).then((res) => {
					console.log("getWareHouseList res", res);
					this.wareHouses = [res.data].map((item) => ({
						...item,
						value: item.backupName,
						text: item.backupName,
					}));
					this.model.wareHouse = this.wareHouses[0]?.value;
					this.model.warehouseId = this.wareHouses[0]?.id;
				});
			},
			getSelectList(e) {},
			itemCodebyNameChange() {
				const that = this;
				if (that.model.itemCodebyName) {
					that.model.itemCodebyList = that.data.itemCodebyName
						.split(",")
						.map((item) => {
							let obj = {};
							if (typeof item === "string") {
								obj = {
									itemCode: item,
								};
							} else {
								obj = item;
							}
							return obj;
						});
					that.model.numberOfPiece = that.model.itemCodebyList.length;
					that.model.reportedQuantity = that.model.itemCodebyList.length;
				}
			},
			quantitySChange() {
				const that = this;
				const quantityS = Array.from
					.call({}, that.model.quantityS)
					.map((item) => (item ? parseFloat(item) : 0));
				console.log(quantityS, 'quantityS')
				const num = quantityS.reduce((accumulator, currentValue) => {
					const returns = accumulator + currentValue;
					return returns;
				});
				if (this.model.mode == '正常') {
					that.model.reportedQuantity = Math.floor(num * Math.pow(10, 3)) / Math.pow(10, 3);
				}
				if (that.model.specificationsNumber != 0) {
					that.model.num = Math.floor(num / that.model.specificationsNumber);
					that.model.boxes = num - that.model.num * that.model.specificationsNumber;
				}
			},
			submit() {
				const that = this;
				this.$refs.uForm.validate().then((valid) => {
					if (valid) {
						that.$loading.open();
						const quantityS = Array.from
							.call({}, that.model.quantityS)
							.map((item) => (item ? parseFloat(item) : 0));

						if (that.model.mode === "箱码") {
							const num = quantityS.reduce((accumulator, currentValue) => {
								const returns = accumulator + currentValue;
								return returns;
							});

							if (num != that.model.reportedQuantity) {
								uni.$emit("openToast", {
									type: "error",
									title: "提报数量之和要等于报工数量",
								});
								return;
							}
						}

						if (!this.data.cuttingPlanCode) {
							delete that.model.rollNumber;
							delete that.model.rollWeight;
						}
						const data = {
							...that.model,
							workCode: that.id,
							operatorNumber: that.selectList,
							quantityS: quantityS,
							imagePath: that.fileList.map((item) => {
								return {
									...item,
									fileName: item.fileName,
									filePath: item.url,
									fileUrl: item.url,
								};
							}),
						}
						this.loading = true;
						fetch("post", "/dms/mobile/addReporting", data).then((data) => {
							console.log("imagePath-----------");
							this.loading = false;
							that.$loading.close();
							uni.setStorageSync("getSelectList", null);
							uni.setStorageSync("getSelectLists", null);

							uni.$emit("openToast", {
								type: "success",
								title: "申请成功",
								complete() {
									uni.navigateBack({
										delta: 1,
									});
								},
							});
						});
					} else {}
				});
			},
		},
		// destroyed() {
		//   uni.setStorageSync("getSelectList", null);
		// },
	};
</script>

<style scoped lang="scss">
	.isThis {
		border: 1px solid #f17a0a !important;
	}

	.device-details {
		height: 100%;
		overflow: auto;
		padding-bottom: 150rpx;

		.content {
			min-height: 100%;
		}

		.title {
			font-size: 32rpx;
			margin-bottom: 20rpx;
			padding: 0 40rpx 20rpx 40rpx;
			border-bottom: 1px solid #e0e0e0;
			display: flex;
			align-items: center;

			.txt {
				flex: 1;
			}

			.tag-box {
				display: flex;
				align-items: center;
			}
		}

		.content-top {
			padding: 40rpx;

			.state {
				color: #f17a0a;
				margin-bottom: 20rpx;
			}
		}

		.select_user {
			display: flex;
			font-size: 30rpx;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 40rpx;
		}

		.text-box-l {
			display: flex;
			justify-content: space-between;
			align-items: center;
			flex: 1;
			overflow: hidden;

			.label {
				min-width: 60px;
			}
		}

		.txt-box {
			overflow: auto;
			flex: 1;
			white-space: nowrap;
			max-width: 100%;
			flex-wrap: inherit;
			text-align: right;

			.txt {
				margin-right: 5px;
			}
		}

		.search-box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 60rpx;

			.label {
				margin: 0 20rpx;
			}
		}
	}

	.u-textarea--disabled {
		pointer-events: none;
		user-select: none;
		background: #fff;
		border-color: #eee;
	}

	.item-code-list {
		padding: 0 40rpx;
		display: flex;
		flex-direction: column;

		.item-code-item {
			display: flex;
			align-items: center;
			padding: 20rpx 0;
			border-bottom: 1px solid #f5f5f5;

			.item-label {
				width: 150rpx;
				margin-right: 20rpx;
				flex-shrink: 0; // 防止压缩
			}

			.item-value {
				flex: 1;
				margin-right: 20rpx;
				word-break: break-all;
			}

			.delete-btn {
				padding: 8rpx 20rpx;
				background-color: #f56c6c;
				color: white;
				border-radius: 6rpx;
				font-size: 24rpx;
				white-space: nowrap;
			}
		}
	}
</style>